package dev.projectnightfall.graphics.states;

import dev.projectnightfall.graphics.RenderEngine;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.input.Keyboard;
import org.newdawn.slick.*;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author root
 */
public class GameplayState extends AGameState {

    private SpriteSheet sheet;
    private Image tileset;

    public GameplayState(int stateID) {
        super(stateID);

        try {
            tileset = new Image("dev/projectnightfall/graphics/resources/sprites/spritesheet.png");
            sheet = new SpriteSheet(tileset, 16, 16, 0, 0);
        } catch (SlickException ex) {
            Logger.getLogger(GameplayState.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void init(GameContainer gc, StateBasedGame game) throws SlickException {
    }

    @Override
    public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException {
        // grass test
        Image cur = sheet.getSprite(1, 0);
        for (int i = 0; i < RenderEngine.COLS; i++) {
            for (int j = 0; j < RenderEngine.ROWS; j++) {
                g.drawImage(cur, i * RenderEngine.SPRITE_SIZE, j * RenderEngine.SPRITE_SIZE);
            }
        }

        g.drawString("Le Gameplay State", 100, 100);
        g.drawString("Press ESC to pause", 100, 120);
        g.drawString("Grass, grass, MORE GRASS!", 50, 50);
    }

    @Override
    public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException {
        Input in = gc.getInput();
        in.disableKeyRepeat();

        if (in.isKeyDown(Keyboard.KEY_ESCAPE)) {
            // Enter pause state
            game.enterState(RenderEngine.PAUSESTATE);
        }
    }
}
